<?php
//供应商
namespace Common\Model;

class UserKuerpWarehouseLocProductModel extends UserKuerpWarehouseModel {

	//追加属性
    public $append = [
        'wh_name',          //仓库名称
        'loc_name',         //库位名称
        'goods_name',     //商品名
        //'product',     //商品信息
        'stock',       //库存数量
	];

    /**
     * 库存数量
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getStockAttr($value, $data){
		return floatval($data['stock']);
    }

    /**
     * 仓库信息
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getWhNameAttr($value, $data){
        $name = '';
		$model = M('UserKuerpWarehouse');
		$wdata['id'] = $data['wh_id'];
		$name = $model->where($wdata)->getField('name') ? : '';
		return $name;
    }

    /**
     * 库位信息
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getLocNameAttr($value, $data){
        $name = '';
		$model = M('UserKuerpWarehouseLocation');
		$wdata['id'] = $data['loc_id'];
		$name = $model->where($wdata)->getField('loc_name') ? : '';
		return $name;
    }

    /**
     * 商品信息
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getGoodsNameAttr($value, &$data){
        $model = M('UserGoodsAttr');
        $wdata['id'] = $data['item_id'];
        $vo = $model->where($wdata)->find();
        $data['goods_name'] = $vo['goods_name'];
        $data['guige_name'] = $vo['guige_name'];
        $data['color'] = $vo['color'];
        $data['goods_attr'] = $vo['goods_attr'];
        $data['chenfen'] = $vo['chenfen'];
        $data['unit'] = $vo['unit'];
        return $vo['goods_name'];
    }

    /**
     * 商品信息
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getProductAttr($value, &$data){
        $model = D('UserGoodsAttr');
        $wdata['id'] = $data['item_id'];
        $vo = $model->where($wdata)->find();
        return $vo;
    }

   
}

?>